package cn.rwklyd.BookKeeping.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
 * @author 键盘书生
 * @date 2024/10/13
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**") //允许所有路径
                .allowedOriginPatterns("*")  // 允许的域名
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("*")  // 允许的请求头
                .allowCredentials(true)  // 允许携带cookie
                .maxAge(3600);  // 设置预检请求的缓存时间
    }
}
